package com.ssy.lingxi.contract.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.contract.model.vo.common.response.StatusItemVO;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 请款单状态枚举
 * @author 伍将
 * @date 2021/3/9
 * @version 2.0.0
 */
public enum ApplyAmountOrderStatusEnum {

    /**
     * 全部 - 0
     */
    ALL(0, "全部"),
    /**
     * 待提交审核 - 1
     */
    TO_BE_SUBMIT_EXAMINE(1, "待提交审核"),
    /**
     * 待审核(一级) - 2
     */
    TO_BE_EXAMINE_1(2, "待审核(一级)"),
    /**
     * 审核不通过(一级)
     */
    EXAMINE_NO_PASS_1(3, "审核不通过(一级)"),
    /**
     * 待审核(二级) - 4
     */
    TO_BE_EXAMINE_2(4, "待审核(二级)"),
    /**
     * 审核不通过(二级) - 5
     */
    EXAMINE_NO_PASS_2(5, "审核不通过(二级)"),
    /**
     * 待提交财务付款 - 6
     */
    TO_BE_SUBMIT_PAY(6, "待提交财务付款"),
    /**
     * 待付款 - 7
     */
    TO_BE_PAY(7, "待付款"),
    /**
     * 已付款 - 8
     */
    PAY(8, "已付款"),
    /**
     * 已作废 - 9
     */
    INVALID(9, "已作废");

    private final Integer code;
    private final String message;

    ApplyAmountOrderStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getClass(), this.code);
    }

    public static String getMessage(Integer code) {
        ApplyAmountOrderStatusEnum item = Arrays.stream(ApplyAmountOrderStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);

        return null != item ? item.getMessage() : "";
    }

    /**
     * 获得所有状态项列表
     * @param excludeCodes 排除的code/不排除传null
     * @return
     */
    public static List<StatusItemVO> all(List<Integer> excludeCodes){
        Stream<ApplyAmountOrderStatusEnum> stream = Arrays.stream(ApplyAmountOrderStatusEnum.values());
        if(excludeCodes!=null&&excludeCodes.size()>0){
            stream=stream.filter(o->!excludeCodes.contains(o.getCode()));
        }
        return stream.map(o ->{
            StatusItemVO vo=new StatusItemVO();
            vo.setCode(o.getCode());
            vo.setMessage(o.getMessage());
            return vo;
        }).collect(Collectors.toList());
    }
}
